package com.zys;

import com.zys.config.TestMapper;
import com.zys.config.UserConfig;
import com.zys.event.CustomSpringEventPublisher;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@SpringBootApplication
@EnableCaching
public class MybatisPlusDemoApplication implements CommandLineRunner {

    @Resource
    private CustomSpringEventPublisher publisher;


    public static void main(String[] args) {
        SpringApplication.run(MybatisPlusDemoApplication.class, args);
//        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        // 如果你的配置类是AppConfig.class, 请替换下面的参数为你自己的配置类
//        context.register(TestMapper.class);
//        context.refresh(); // 确保在获取任何bean之前调用refresh()
//        TestMapper userConfig = (TestMapper) context.getBean("userConfig");
//        userConfig.test();
    }

    @Override
    public void run(String... args) throws Exception {
        publisher.publishCustomEvent("Hello, Spring Event!");
    }
}
